package 笔试.望望;

import java.util.HashMap;

/**
 * @author:谢君臣
 * @Date:2021/10/23-19:39
 * @version:1.0
 * @function:
 */
public class Main {
    public static void main(String[] args) {
       // System.out.println(query(new int[]{1, 2, 2, 4, 4, 4, 6, 6, 7}, 2));
    }

    public static int query(int[] arr, int time) {
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < arr.length; i++) {
            int num = arr[i];
            if (!map.containsKey(num)) map.put(num, i);
            hashMap.put(num, hashMap.getOrDefault(num, 0) + 1);

        }
        int res = -1, max = arr[0];
        for (Integer key : hashMap.keySet()) {
            if (hashMap.get(key) == time && key > max) {
                res = map.get(key);
                max = key;
            }
        }
        return res;
    }

}
